import {defineStore} from 'pinia'
import {ChatUser} from "@/types/userTypes";
import {UserMessage} from "@/types/webSocketMessageTypes";

// 第一个参数是应用程序中 store 的唯一 id
export const chatInfoStore = defineStore('chatInfoStore', {
    state: () => {
        let chatUser: ChatUser = {
            chatUserId: '',
            chatUserName: '',
            content: 0
        }
        let chatUsers: any = {}
        let userMessages: UserMessage[] = []
        return {
            // 所有这些属性都将自动推断其类型
            chatUser: chatUser,
            chatUsers: chatUsers,
            userMessages: userMessages,
        }
    },
    actions: {
        setChatUsers(chatUsers: any) {
            for (const key in chatUsers) {
                if (this.chatUsers[key]) {
                    chatUsers[key].content = this.chatUsers[key].content;
                }
            }
            this.chatUsers = chatUsers;
        }
    },
    persist: true,
})